package cn.com.taurus.controller.datatable;

import cn.com.taurus.bean.DealMessageBean;
import cn.com.taurus.biz.AdminLogBiz;
import cn.com.taurus.biz.DealMessageBiz;
import cn.com.taurus.biz.FundCompanyBiz;
import cn.com.taurus.entity.AdminLog;
import cn.com.taurus.entity.DealMessage;
import cn.com.taurus.entity.FundCompany;
import cn.com.taurus.util.Log;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author zjw
 * @createTime 2021年6月28日
 * @remark 交易申请控制层
 * @version 1.0
 */
@Controller
public class DealMessageController {
    @Autowired
    DealMessageBiz dealMessageBiz;

    @RequestMapping("/dealMessage")
    public String dealMessage() {
        return "datatable/dealMessage";
    }

    @RequestMapping("/updateDealMessage")
    @Log(operation = "修改交易申请信息",type = 2)
    public String updateDealMessage(@ModelAttribute DealMessage dealMessage){
        dealMessageBiz.buyApplicationUpdate(dealMessage);
        return "datatable/dealMessage";
    }

    @RequestMapping("/deleteDealMessage")
    @Log(operation = "删除交易申请信息",type = 3)
    public String deleteDealMessage(Integer dmId){
        dealMessageBiz.buyApplicationDelete(dmId);
        return "datatable/dealMessage";
    }

    /**
     * 模糊查询
     * @param pageNum 几条
     * @param pageSize 数量
     * @param caId 客户账户编号
     * @param fId 基金编号
     * @param applyBuy 申请购买金额
     * @param applyTime 申请时间
     * @return
     */
    @ResponseBody
    @RequestMapping("/conditionSelectDealMessage")
    @Log(operation = "条件查询交易申请信息",type = 1)
    public HashMap conditionSelectDealMessage(Integer pageNum, Integer pageSize, String caId, String fId, String applyBuy,String applyTime,String time){
        System.out.println(time);
        System.out.println(applyTime);
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<DealMessageBean> rule = dealMessageBiz.conditionSelectDealMessage(caId,fId,applyBuy,applyTime,time);;
        PageInfo<DealMessageBean> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        return map;
    }

    /**
     * 分页
     * @param pageNum
     * @param pageSize
     * @return
     */
    @ResponseBody
    @RequestMapping("/selectFundDealMessage")
    public HashMap selectFundDealMessage(Integer pageNum,Integer pageSize){
        HashMap<String, Object> map = new HashMap<>();
        // 开启分页支持
        PageHelper.startPage(pageNum,pageSize);
        List<DealMessage> rule = dealMessageBiz.buyApplicationSelectAll();
        PageInfo<DealMessage> pageInfo = new PageInfo<>(rule);
        System.out.println("数据："+pageInfo.getPages());
        map.put("code",0);
        map.put("msg","请求成功");
        //count：总数据条数
        map.put("count",pageInfo.getTotal());
        //data：数据
        map.put("data",pageInfo.getList());
        System.out.println(map);
        return map;
    }
}
